Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IntervalStyle::MySQL #18

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Conversation

sgrebnov
Copy link

@sgrebnov sgrebnov commented Jul 18, 2024

Which issue does this PR close?

PR implements support for IntervalStyle::MySQL

This fixes spiceai/spiceai#1950

MySQL Interval specification: https://dev.mysql.com/doc/refman/8.4/en/expressions.html#temporal-intervals

Note:

MySQL supports the DAY_MICROSECOND unit type (format is DAYS HOURS:MINUTES:SECONDS.MICROSECONDS), which can be used to optimize the number of INTERVAL elements for complex cases. The decision to use the current version (separate INTERVALs) is made to provide cleaner SQL for typical scenarios where only a few INTERVAL elements are used (day, hours, etc.).

The implementation has been updated to generate single INTERVAL expression as generated intervals sequence can't be wrapped in brackets - (INTERVAL 1 YEAR + INTERVAL 1 MONTH ...) so we need single expression so it works correct for interval subtraction cases

@sgrebnov sgrebnov self-assigned this Jul 18, 2024
datafusion/sql/src/unparser/expr.rs Show resolved Hide resolved
datafusion/sql/src/unparser/expr.rs Outdated Show resolved Hide resolved
datafusion/sql/src/unparser/expr.rs Outdated Show resolved Hide resolved
@sgrebnov sgrebnov marked this pull request as draft July 18, 2024 08:20
@sgrebnov sgrebnov marked this pull request as ready for review July 18, 2024 19:32
@sgrebnov sgrebnov merged commit d0943b9 into spiceai-40 Jul 19, 2024
@sgrebnov sgrebnov deleted the sgrebnov/mysql-interval branch July 19, 2024 06:20
sgrebnov added a commit that referenced this pull request Jul 22, 2024
y-f-u pushed a commit that referenced this pull request Jul 29, 2024
* Configurable date field extraction style for unparsing (#21)

* Add support for IntervalStyle::MySQL (#18)

* Support alternate format for Int64 unparsing (SIGNED for MySQL) (#22)

* Alternate format support for Timestamp casting (DATETIME for MySQL) (#23)

* Improve

* Fix clippy and docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants